﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PraceDyplomowe2.Models;

namespace PraceDyplomowe2.Controllers
{
    //[Authorize(Roles = "Student")]
    public class ProfilStudentaController : Controller
    {
        private PraceDyplomoweEntities db = new PraceDyplomoweEntities();

        //
        // GET: /ProfilStudenta/

		[Authorize(Roles = "Dziekan, Promotor")]
        public ActionResult Index(int? id)
        {
            return View(db.UserProfiles.Where(up => up.Rola.Nazwa == Rola.StudentNazwa).ToList());
        }

        //
        // GET: /ProfilStudenta/Details/

        public ActionResult Details(int id = 0)
        {
			if (id == 0)
			{
				return View(db.UserProfiles.Single(up => up.UserName == User.Identity.Name));
			}

			UserProfile student = db.UserProfiles.Find(id);
			if (student == null)
			{
				return HttpNotFound();
			}

			return View(student);
        }

        //
        // GET: /ProfilStudenta/Create/

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Tematy/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(UserProfile student)
        {
            if (ModelState.IsValid)
            {
                db.UserProfiles.Add(student);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(student);
        }

    }
}
